unit MBFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TMBForm = class(TForm)
    lblText: TLabel;
    procedure FormCreate(Sender: TObject);
  private
    FCoverControl: TControl;
    FRect: TRect;
    procedure SetCoverControl(const Value: TControl);
    procedure SetRect(const Value: TRect);
  public
    class function MBControl(AControl: TControl; AText: string): TMBForm;
    class function MBRect(ARect: TRect; AControl: TControl; AText: string): TMBForm;
    property CoverControl: TControl read FCoverControl write SetCoverControl;
    property Rect: TRect read FRect write SetRect;
  end;



implementation

{$R *.dfm}

procedure TMBForm.FormCreate(Sender: TObject);
var
  l:longint;
begin
  l:=getWindowLong(Handle, GWL_EXSTYLE);
  l := l Or WS_EX_LAYERED;
  SetWindowLong(handle, GWL_EXSTYLE, l);
  SetLayeredWindowAttributes(handle, 0, 180, LWA_ALPHA);
end;

class function TMBForm.MBControl(AControl: TControl; AText: string): TMBForm;
var
  oPoint: TPoint;
begin
  Result := Self.Create(AControl);
  oPoint.X := AControl.Left;
  oPoint.Y := AControl.Top;
  oPoint := AControl.Parent.ClientToScreen(oPoint);
  Result.Top := oPoint.Y;
  Result.Left := oPoint.X;
  Result.Width := AControl.Width;
  Result.Height := AControl.Height;
  Result.lblText.Caption := AText;
  Result.CoverControl := AControl;
  Result.Show;
  Result.BringToFront;
end;

class function TMBForm.MBRect(ARect: TRect; AControl: TControl; AText: string):
    TMBForm;
var
  oPoint: TPoint;
begin
  Result := Self.Create(nil);
  oPoint.X := ARect.Left;
  oPoint.Y := ARect.Top;
  oPoint := AControl.ClientToScreen(oPoint);
  Result.Top := oPoint.Y;
  Result.Left := oPoint.X;
  Result.Width := (ARect.Right - ARect.Left);
  Result.Height := (ARect.Bottom - ARect.Top);
  Result.lblText.Caption := AText;
  Result.CoverControl := nil;
  Result.Rect := ARect;
  Result.Show;
  Result.BringToFront;
end;

procedure TMBForm.SetCoverControl(const Value: TControl);
begin
  FCoverControl := Value;
end;

procedure TMBForm.SetRect(const Value: TRect);
begin
  FRect := Value;
end;

end.
